﻿namespace Chain.BLL
{
    using Chain.DAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class Proposal
    {
        private readonly Chain.DAL.Proposal dal = new Chain.DAL.Proposal();

        public int Add(Chain.Model.Proposal model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.Proposal> DataTableToList(DataTable dt)
        {
            List<Chain.Model.Proposal> list = new List<Chain.Model.Proposal>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.Proposal item = new Chain.Model.Proposal();
                    if ((dt.Rows[i]["ProposalID"] != null) && (dt.Rows[i]["ProposalID"].ToString() != ""))
                    {
                        item.ProposalID = int.Parse(dt.Rows[i]["ProposalID"].ToString());
                    }
                    if ((dt.Rows[i]["ProposalContent"] != null) && (dt.Rows[i]["ProposalContent"].ToString() != ""))
                    {
                        item.ProposalContent = dt.Rows[i]["ProposalContent"].ToString();
                    }
                    if ((dt.Rows[i]["MemID"] != null) && (dt.Rows[i]["MemID"].ToString() != ""))
                    {
                        item.MemID = new int?(int.Parse(dt.Rows[i]["MemID"].ToString()));
                    }
                    if ((dt.Rows[i]["MemMobile"] != null) && (dt.Rows[i]["MemMobile"].ToString() != ""))
                    {
                        item.MemMobile = dt.Rows[i]["MemMobile"].ToString();
                    }
                    if ((dt.Rows[i]["ProposalTime"] != null) && (dt.Rows[i]["ProposalTime"].ToString() != ""))
                    {
                        item.ProposalTime = new DateTime?(DateTime.Parse(dt.Rows[i]["ProposalTime"].ToString()));
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int ProposalID)
        {
            return this.dal.Delete(ProposalID);
        }

        public bool DeleteList(string ProposalIDlist)
        {
            return this.dal.DeleteList(ProposalIDlist);
        }

        public bool Exists(int ProposalID)
        {
            return this.dal.Exists(ProposalID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public Chain.Model.Proposal GetModel(int ProposalID)
        {
            return this.dal.GetModel(ProposalID);
        }

        public List<Chain.Model.Proposal> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public DataSet GetProposalInfo(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetProposalInfo(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.Proposal model)
        {
            return this.dal.Update(model);
        }
    }
}

